package sctu.edu.java.year2016.team08.lisonghong.day20160616.chapter12_2;

import java.io.*;
import java.util.Scanner;

/**
 * Created by 松红 on 2016/6/16.
 * 用字符输入、输出流读取文件，将一段文字加密后存入文件，在后再读取，并将加密前的文件与
 * 加密后的文件输出。。
 */
public class PasswordFile {
    public static void main(String[] args) {
        File file = new File("D:/word1.txt");
        if (file.exists()) {
            try {
                FileWriter out = new FileWriter(file);
                Scanner input = new Scanner(System.in);
                System.out.println("输入文件信息：");
                String string = input.nextLine();
                out.write(string);
                char[] a = string.toCharArray();
                for (int i = 0; i < a.length; i += 2) {
                    a[i] = '*';
                }
                out.write(a);
                out.close();
                FileReader in = new FileReader("D:/word1.txt");
                char byt[] = new char[1024];
                int len = in.read(byt);
                System.out.println("未加密文件信息：\n" + new String(byt, 0, string.length()));
                System.out.println("已加密文件信息：\n" + new String(byt, string.length(), a.length));

                in.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("ok!created!");
            }
        }
    }
}
